home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / PNL Libraries / MySpeak.p < prev    next >
Encoding:
Text File  |  1995-10-23  |  1.4 KB  |  84 lines  |  [TEXT/CWIE]

  1. unit MySpeak;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types;
  7.  
  8.     procedure StartupSpeak;
  9.     function SpeakBusy: boolean;
  10.     procedure SpeakStr (s: Str255);
  11.     procedure Speak (id, index: integer);
  12.     function SpeechAvailable: boolean;
  13.  
  14. implementation
  15.  
  16.     uses
  17.         Speech, GestaltEqu, TextUtils, CodeFragments,
  18.         MyStartup;
  19.  
  20. {$SETC debug=0}
  21.  
  22.     function HasSpeechLib:boolean;
  23.     begin
  24. {$IFC GENERATINGPOWERPC}
  25.         HasSpeechLib := longint(@SpeakString) <> kUnresolvedCFragSymbolAddress;
  26. {$ELSEC}
  27.         HasSpeechLib := true;
  28. {$ENDC}
  29.     end;
  30.  
  31.     function SpeechAvailable: boolean;
  32.         var
  33.             v: longint;
  34.     begin
  35. {$IFC debug}
  36.         SpeechAvailable := true;
  37. {$ELSEC}
  38.         SpeechAvailable := (Gestalt(gestaltSpeechAttr, v) = noErr) & BTST(v, gestaltSpeechMgrPresent) & HasSpeechLib;
  39. {$ENDC}
  40.     end;
  41.  
  42.     function SpeakBusy: boolean;
  43.     begin
  44. {$IFC debug}
  45.         SpeakBusy := false;
  46. {$ELSEC}
  47.         SpeakBusy := SpeechAvailable & (SpeechBusy > 0);
  48. {$ENDC}
  49.     end;
  50.  
  51.     procedure SpeakStr (s: Str255);
  52.     begin
  53. {$IFC debug}
  54.         DebugStr(concat('Speak ', s));
  55. {$ELSEC}
  56.         if not SpeechAvailable | (SpeakString(@s) <> noErr) then begin
  57.             SysBeep(1);
  58.         end;
  59. {$ENDC}
  60.     end;
  61.  
  62.     procedure Speak (id, index: integer);
  63.         var
  64.             s: Str255;
  65.     begin
  66.         GetIndString(s, id, index);
  67.         SpeakStr(s);
  68.     end;
  69.  
  70.     procedure FinishSpeak;
  71.     begin
  72. {$IFC not debug}
  73.         if SpeechAvailable then begin
  74.             SpeakStr('');
  75.         end;
  76. {$ENDC}
  77.     end;
  78.  
  79.     procedure StartupSpeak;
  80.     begin
  81.         SetStartup(nil, nil, 0, FinishSpeak);
  82.     end;
  83.     
  84. end.